cd E:\data\cooperation\poor\submission_gini\data  /*data path*/
****************original data************************
use da_original,clear  
egen idd = group(id)
xtset idd year
gen vdem_egaldem_2=vdem_egaldem^2
gen l_wdi_gdp=ln(wdi_gdpcapcon2010)
gen l_wdi_fdiin=ln(wdi_fdiin)
gen l_unna_pop=ln(unna_pop)
gen l_wdi_area=ln(wdi_area)
gen l_wdi_refori=ln(wdi_refori)
/*year and country*/
label var year "Year"
label var id "country code"
label var pov9	"Gini Index"
label var vdem_egaldem "Egalitarian democracy index"
label var l_unna_pop "The log of population"
label var wdi_lfpf "Labor force, female (% of total labor force)"
label var dr_sg "social globalization"
label var wdi_araland "Arable land (% of land area)"
label var wdi_agedr "Age dependency ratio (% of working-age population)"
label var wdi_tele "Landline subscriptions (per 100 people)"
label var wdi_poprul "Rural population (% of total population)"
label var wdi_internet "Individuals using the Internet (% of population)"
label var wdi_unempfilo "Unemployment, female (% of female labor force)"
label var l_wdi_gdp	"The log of GDP per Capital"
label var p_durable	"Regime Durability"
label var ht_colonial	"Colonial Origin"
label var dpi_system	"Political System"
label var l_wdi_fdiin	"The log of Foreign direct investment, net inflows (% of GDP)" 
label var l_wdi_refori "Refugee population by country or territory of origin"




des pov9 vdem_egaldem l_unna_pop   wdi_araland wdi_agedr l_wdi_gdp wdi_unempfilo wdi_internet  wdi_tele ///
dr_sg p_durable  l_wdi_fdiin wdi_poprul l_wdi_refori  ht_colonial dpi_system  
******************************************************************
 sum pov9 vdem_egaldem l_unna_pop   wdi_araland wdi_agedr l_wdi_gdp wdi_unempfilo wdi_internet  wdi_tele ///
dr_sg p_durable  l_wdi_fdiin wdi_poprul l_wdi_refori  ht_colonial dpi_system 

collin vdem_egaldem l_unna_pop   wdi_araland wdi_agedr l_wdi_gdp wdi_unempfilo wdi_internet  wdi_tele ///
dr_sg p_durable  l_wdi_fdiin wdi_poprul l_wdi_refori 

*   xtunitroot fisher pov9, pperron lags(2) /*can not take the unitroot test*/

 xtreg l(0/1).pov9 vdem_egaldem,fe 
 est store fe
xtreg l(0/1).pov9 vdem_egaldem l_unna_pop   wdi_araland wdi_agedr l_wdi_gdp wdi_unempfilo wdi_internet  wdi_tele ///
dr_sg p_durable  l_wdi_fdiin wdi_poprul l_wdi_refori ,fe
 est store fe1
 xtreg l(0/1).pov9 vdem_egaldem l_unna_pop   wdi_araland wdi_agedr l_wdi_gdp wdi_unempfilo wdi_internet  wdi_tele ///
dr_sg p_durable  l_wdi_fdiin wdi_poprul l_wdi_refori ,re
 est store re

 xtreg l(0/1).pov9 vdem_egaldem vdem_egaldem_2 l_unna_pop   wdi_araland wdi_agedr l_wdi_gdp wdi_unempfilo wdi_internet  wdi_tele ///
dr_sg p_durable  l_wdi_fdiin wdi_poprul l_wdi_refori  ,fe
 est store fe2
 xtreg l(0/1).pov9 vdem_egaldem  l_unna_pop   wdi_araland wdi_agedr l_wdi_gdp wdi_unempfilo wdi_internet  wdi_tele ///
dr_sg p_durable l_wdi_fdiin wdi_poprul l_wdi_refori  i.year ,fe
 est store fe3
  xtivreg l(0/1).pov9 (vdem_egaldem= vdem_polyarchy p_polity2 vdem_libdem) l_unna_pop   wdi_araland wdi_agedr l_wdi_gdp wdi_unempfilo wdi_internet  wdi_tele ///
dr_sg p_durable  l_wdi_fdiin ,fe
xtoverid
dmexogxt
est store iv3
 hausman  fe3 re
 hausman  fe2 re
 hausman  fe1 re
 esttab fe fe1 re fe2 fe3 iv3, cells(b(star fmt(4)) t(par fmt(2))) /// 
legend label  varwidth(50) varlabels(_cons constant) mtitles("FE" "FE" "RE" "FE" "FE" "IV-FE") /// 
stats(N r2, fmt(0 3) label(Observation R-squared )) star(* 0.10 ** 0.05 *** 0.01)  /*table 4*/
 
pwcorr_a vdem_egaldem vdem_polyarchy p_polity2 vdem_libdem ,star1(0.1) star5(0.05) star10(0.01)

 

 **********panel B**********
 use da_interpolation,clear  
egen idd = group(id)
egen y=group(year)
xtset idd year
gen vdem_egaldem_2=vdem_egaldem^2
gen l_wdi_gdp=ln(wdi_gdpcapcon2010)
gen l_wdi_fdiin=ln(wdi_fdiin)
gen l_imf_infl=ln(imf_infl)
gen l_unna_pop=ln(unna_pop)
gen l_wdi_area=ln(wdi_area)
gen l_wdi_refori=ln(wdi_refori)
label var year "Year"
label var id "country code"
label var pov9	"Gini Index"
label var vdem_egaldem "Egalitarian democracy index"
label var l_unna_pop "The log of population"
label var wdi_lfpf "Labor force, female (% of total labor force)"
label var dr_sg "social globalization"
label var wdi_araland "Arable land (% of land area)"
label var wdi_agedr "Age dependency ratio (% of working-age population)"
label var wdi_tele "Landline subscriptions (per 100 people)"
label var wdi_poprul "Rural population (% of total population)"
label var wdi_internet "Individuals using the Internet (% of population)"
label var wdi_unempfilo "Unemployment, female (% of female labor force)"
label var l_wdi_gdp	"The log of GDP per Capital"
label var p_durable	"Regime Durability"
label var ht_colonial	"Colonial Origin"
label var dpi_system	"Political System"
label var l_wdi_fdiin	"The log of Foreign direct investment, net inflows (% of GDP)" 
label var l_wdi_refori "The log of Refugee population by country or territory of origin"
label var wdi_popden "Population density (people per sq. km of land area)"
sum pov9 

collin vdem_egaldem l_unna_pop  wdi_araland wdi_agedr l_wdi_gdp wdi_unempfilo wdi_internet  wdi_tele ///
dr_sg p_durable  l_wdi_fdiin wdi_poprul l_wdi_refori 

xtunitroot fisher pov9,pperron lags(2) /*unitroot test*/

 xtgls pov9 vdem_egaldem l_unna_pop   wdi_araland wdi_agedr l_wdi_gdp wdi_unempfilo wdi_internet  wdi_tele ///
dr_sg p_durable  l_wdi_fdiin wdi_poprul l_wdi_refori  i.year
 est store gls
 xtreg l(0/1).pov9 vdem_egaldem,fe
 est store fe
xtreg l(0/1).pov9 vdem_egaldem l_unna_pop   wdi_araland wdi_agedr l_wdi_gdp wdi_unempfilo wdi_internet  wdi_tele ///
dr_sg p_durable  l_wdi_fdiin wdi_poprul l_wdi_refori ,fe
 est store fe1
 xtreg l(0/1).pov9  vdem_egaldem l_unna_pop   wdi_araland wdi_agedr l_wdi_gdp wdi_unempfilo wdi_internet  wdi_tele ///
dr_sg p_durable  l_wdi_fdiin wdi_poprul l_wdi_refori  ,re
 est store re
 hausman fe1 re
 xtreg l(0/1).pov9 vdem_egaldem  l_unna_pop   wdi_araland wdi_agedr  wdi_unempfilo l_wdi_gdp wdi_internet  wdi_tele ///
dr_sg p_durable  l_wdi_fdiin wdi_poprul l_wdi_refori  i.year ,fe
 est store fe3
 esttab fe gls fe1 re fe3, cells(b(star fmt(4)) t(par fmt(2))) /// 
legend label  varwidth(50) varlabels(_cons constant) mtitles("FE" "FGLS" "FE" "RE" "FE" ) /// 
stats(N r2, fmt(0 3) label(Observation R-squared )) star(* 0.10 ** 0.05 *** 0.01)  /*table 5*/ 
 
 
 
  ****************dynamic panel data analysis*****************
 xtdpdsys pov9 vdem_egaldem l_unna_pop   wdi_araland  wdi_unempfilo, lags(1) twostep  artests(2)
 est store dpd
predict res5, e
xtcd2 res5
xtabond2 L(0/1).pov9 vdem_egaldem l_unna_pop  wdi_araland wdi_unempfilo , ///
gmm(L.pov9 vdem_egaldem l_unna_pop  wdi_araland wdi_unempfilo)  robust twostep small h(2) 

xtcd2 
est store gmm
 xtdcce2 d.pov9 d.vdem_egaldem  ,lr( ///
   l_unna_pop  wdi_araland wdi_unempfilo ) p(L.pov9  l_unna_pop   wdi_araland wdi_unempfilo ) ///
  cr(d.pov9 d.vdem_egaldem l_unna_pop   wdi_araland wdi_unempfilo ) nocross lr_options(xtpmgnames) 
est store cce3
esttab dpd gmm cce3, cells(b(star fmt(4)) t(par fmt(2))) /// 
legend label  varwidth(50) varlabels(_cons constant) mtitles("DPD" "GMM" "CCEMG") /// 
stats(N r2, fmt(0 3) label(Observation R-squared )) star(* 0.10 ** 0.05 *** 0.01) 
 
 
 
 
 
 ***********colonical analysis****************
preserve
keep if ht_colonial==0
xtreg l(0/1).pov9 vdem_egaldem  l_unna_pop   wdi_araland wdi_agedr l_wdi_gdp wdi_unempfilo wdi_internet  wdi_tele ///
dr_sg p_durable  l_wdi_fdiin wdi_poprul l_wdi_refori  ,fe
est store f
 esttab f, cells(b(star fmt(4)) t(par fmt(2))) /// 
legend label  varwidth(50) varlabels(_cons constant) mtitles("FE") /// 
stats(N r2, fmt(0 3) label(Observation R-squared ))  star(* 0.10 ** 0.05 *** 0.01) 
restore

preserve
keep if ht_colonial==1
xtreg l(0/1).pov9 vdem_egaldem  l_unna_pop   wdi_araland wdi_agedr l_wdi_gdp wdi_unempfilo wdi_internet  wdi_tele ///
dr_sg p_durable  l_wdi_fdiin wdi_poprul l_wdi_refori  ,fe
est store f
 esttab f, cells(b(star fmt(4)) t(par fmt(2))) /// 
legend label  varwidth(50) varlabels(_cons constant) mtitles("FE") /// 
stats(N r2, fmt(0 3) label(Observation R-squared ))  star(* 0.10 ** 0.05 *** 0.01)
restore
 
gen colonial_vem=ht_colonial*vdem_egaldem
 
xtreg l(0/1).pov9 vdem_egaldem  colonial_vem l_unna_pop   wdi_araland wdi_agedr l_wdi_gdp wdi_unempfilo wdi_internet  wdi_tele ///
dr_sg p_durable  l_wdi_fdiin wdi_poprul l_wdi_refori  i.year,fe
 est store inf
 esttab inf, cells(b(star fmt(4)) t(par fmt(2))) /// 
legend label  varwidth(50) varlabels(_cons constant) mtitles("FE"  ) /// 
stats(N r2, fmt(0 3) label(Observation R-squared )) star(* 0.10 ** 0.05 *** 0.01) /*table 3*/ 
 
 ************regime analysis******************


preserve
keep if regime_country==0
xtreg l(0/1).pov9 vdem_egaldem l_unna_pop   wdi_araland wdi_agedr l_wdi_gdp wdi_unempfilo wdi_internet  wdi_tele ///
dr_sg p_durable  l_wdi_fdiin wdi_poprul l_wdi_refori  ,fe
est store f
 esttab f, cells(b(star fmt(4)) t(par fmt(2))) /// 
legend label  varwidth(50) varlabels(_cons constant) mtitles("FE") /// 
stats(N r2, fmt(0 3) label(Observation R-squared ))  star(* 0.10 ** 0.05 *** 0.01) 
restore

preserve
keep if regime_country==1
xtreg l(0/1).pov9 vdem_egaldem l_unna_pop regime_change  wdi_araland wdi_agedr l_wdi_gdp wdi_unempfilo wdi_internet  wdi_tele ///
dr_sg p_durable  l_wdi_fdiin wdi_poprul l_wdi_refori  ,fe
est store f
 esttab f, cells(b(star fmt(4)) t(par fmt(2))) /// 
legend label  varwidth(50) varlabels(_cons constant) mtitles("FE") /// 
stats(N r2, fmt(0 3) label(Observation R-squared ))  star(* 0.10 ** 0.05 *** 0.01) 
restore


gen sem_president=.
replace sem_president=0 if dpi_system==1
replace sem_president=1 if dpi_system==2
gen parliamentary=.
replace parliamentary=0 if dpi_system==1
replace parliamentary=1 if dpi_system==3
gen par_vem=parliamentary*vdem_egaldem
gen sempre_vem=sem_president*vdem_egaldem
gen regime_vem=regime_country*vdem_egaldem
 gen regime_change=D.dpi_system
replace regime_change=1 if regime_change==-1
replace regime_change=1 if regime_change==-2
replace regime_change=1 if regime_change==2
table id if regime_change==1  /*list the countries which have the regime changed*/


 xtreg l(0/1).pov9 vdem_egaldem parliamentary  par_vem l_unna_pop   wdi_araland wdi_agedr l_wdi_gdp wdi_unempfilo wdi_internet  wdi_tele ///
dr_sg p_durable  l_wdi_fdiin wdi_poprul l_wdi_refori  i.year,fe
 est store reg1
xtreg l(0/1).pov9 vdem_egaldem  sem_president sempre_vem l_unna_pop   wdi_araland wdi_agedr l_wdi_gdp wdi_unempfilo wdi_internet  wdi_tele ///
dr_sg p_durable  l_wdi_fdiin wdi_poprul l_wdi_refori  i.year,fe
est store reg2
xtreg l(0/1).pov9 vdem_egaldem   regime_vem l_unna_pop  wdi_araland wdi_agedr l_wdi_gdp wdi_unempfilo wdi_internet  wdi_tele ///
dr_sg p_durable  l_wdi_fdiin wdi_poprul l_wdi_refori  ,fe
est store reg3
esttab reg1 reg2 reg3 , cells(b(star fmt(4)) t(par fmt(2))) /// 
legend label  varwidth(50) varlabels(_cons constant)  /// 
stats(N r2, fmt(0 3) label(Observation R-squared )) star(* 0.10 ** 0.05 *** 0.01) 
 
 
 
 



